﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace LanAnh
{
    public partial class frmTimKiem : Office2007Form 
    {
        
        private String sColumnName;
        private String sTable;
        private String sDataCurrent;
        public delegate void PassData(String SearchCondition);
        public PassData passData;
        public frmTimKiem(String stable, String scolumName, String sSelectItem)
        {
            Status.Init();
            InitializeComponent();
            

            txtTimKiem.Text = sSelectItem;
            sColumnName = scolumName;
            sTable = stable;
            sDataCurrent = sSelectItem;                        
        }
        Data data = new Data();
        private void txtTimKiem_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
            if (e.KeyCode == Keys.Enter)
            {
                btnTim_Click(sender, e);
            }
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            if (sColumnName == "rownum")
                MessageBoxEx.Show("Không thể tìm ở cột STT");
            else if (passData != null)
            {
                String dkTim;
                dkTim = " LIKE N'%" + txtTimKiem.Text + "%'";                                                    
                String sSearchCondition = " WHERE " + sColumnName + dkTim;
                passData(sSearchCondition);
            }
            this.Close();
        }

        private void frmTimKiem_Load(object sender, EventArgs e)
        {
            try
            {
                data.autoComplete(txtTimKiem, sTable, sColumnName);
            }catch{}
        }
    }
}
